<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>代理管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mobiscroll.jquery.min.css"/>
    <style>
        .z_status{
            background:url("../img/arrow.png")no-repeat 65% center;
            background-size:0.19rem 0.1rem;
            width:50%;
            height:100%;

        }
        .z_arrow{
            background:url("../img/arrow_o.png")no-repeat 65% center;
            background-size:0.19rem 0.1rem;
            width:50%;
            height:100%;
        }
        .z_type{
            background:url("../img/arrow.png")no-repeat 65% center;
            background-size:0.19rem 0.1rem;
            width:50%;
            height:100%;
        }
        .ef8200{
            background-color:#ef8200;
        }
        .z_co{
            color:#7cc0f0;
        }
    </style>
</head>
<body>
    <div>
        <div class="mb20 bw">
            <p class="flex_sa ptb24 bdb"><span class="z_status tac">状态</span><span class="z_type tac">类型</span></p>
            <!--<div class="dpn sta">-->
                <!--<p class="flex flex_column pl30">-->
                    <!--<span class="ptb24">全部</span>-->
                    <!--<span class="ptb24">启用</span>-->
                    <!--<span class="ptb24">禁止</span>-->
                <!--</p>-->
            <!--</div>-->
            <!--<div class="dpn ty">-->
                <!--<p class="flex flex_column pl30">-->
                    <!--<span class="ptb24">全部</span>-->
                    <!--<span class="ptb24">区代理</span>-->
                    <!--<span class="ptb24">个人代理</span>-->
                <!--</p>-->
            <!--</div>-->
        </div>
        <div class="bw plr30 pt24 z_agent">
            <!--<p class="pt20 flex_sb"><span>代理名称：上官沐风</span><span class="z_co">启用</span></p>-->
            <!--<p class="pt10 col9"><span>手机号：13752311456</span></p>-->
            <!--<p class="pt10 pb30 bdb col9"><span>账号余额：￥123.00</span></p>-->
            <!--<p class="ptb20 flex_a jce">-->
                <!--<span onclick="location.href='zl_edit.html'" class="flex_a"><img src="../img/bianji.png" class="mr10" style="width:0.3rem;height:0.3rem;"><span class="bj mr30">编辑</span></span>-->
                <!--<span class="flex_a"><img src="../img/delete.png" class="mr10" style="width:0.3rem;height:0.31rem;"><span class="z_del">删除</span></span>-->
            <!--</p>-->
        </div>
    </div>
    <p class="tac mt100" style="width:100%;" onclick="location.href='zl_addAgent.html'"><button class="ptb24 font16 colw ef8200 border-r6" style="width:85%;">添加代理</button></p>
</body>
</html>
<script src="../js/jquery.min.js"></script>
<script src="../js/dlc.js"></script>
<script src="../js/mobiscroll.jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script>

    <!---->
    var data=['全部','市级','区级','个人'];

    if(get_save('role')==2){
        data=['全部','区级','个人'];
    }else if(get_save('role')==3){
        data=['全部','个人'];
    }

    $('.z_status').mobiscroll().scroller({
        theme: 'ios',
        wheels:[
            [{
                data:['全部', '启用', '禁止']
            }]
        ],
        display: 'bottom',
        headerText:'状态',
        lang: 'zh',
        onBeforeClose: function (event, inst) {
            if (event.button == 'set') {
                if(event.valueText=='全部'){
                    list("","")
                }else if(event.valueText=='启用'){
                    list(1,"")
                }else{
                    list(2,"")
                }
            }
        }

    });

    $('.z_type').mobiscroll().scroller({
        theme: 'ios',
        wheels:[
            [{
                data:data
            }]
        ],
        display: 'bottom',
        headerText:'类型',
        lang: 'zh',
        onBeforeClose: function (event, inst) {
            if (event.button == 'set') {
                if(event.valueText=='全部'){
                    list("","")
                }else if(event.valueText=='区级'){
                    list("",3)
                }else if(event.valueText=='市级'){
                    list("",2)
                }else if(event.valueText=='个人'){
                    list("",4)
                }
            }
        }

    });

    //    代理列表
    var status=3,role=1
    list("","");
    function list(type,status){
        dlctipbox.loading();
        dlc_request('/api/agent/listAgent', { status:type,role:status }, function(res) {
            console.log(res);
            dlctipbox.clear();
            $('.z_agent').children().remove();
            var html='';
            res.data.forEach(function(item,index){
                html+='<div><p class="pt20 flex_sb"><span>代理名称：'+item.name+'</span><span class="z_co">'+(item.status==1?"启用":"禁用")+'</span></p>\n' +
                    '            <p class="pt10 col9"><span>手机号：'+item.phone+'</span></p>\n' +
                    '            <p class="pt10 pb30 bdb col9"><span>账号余额：￥'+item.wallet+'</span></p>\n' +
                    '            <p class="ptb20 flex_a jce">\n' +
                    '                <span class="flex_a bianji" data-id="'+item.id+'"><img src="../img/bianji.png" class="mr10" style="width:0.3rem;height:0.3rem;"><span class="bj mr30">编辑</span></span>\n' +
                    '                <span class="flex_a delz" data-idx="'+item.id+'"><img src="../img/delete.png" class="mr10" style="width:0.3rem;height:0.31rem;"><span class="z_del">删除</span></span>\n' +
                    '            </p></div>'
            })
            $('.z_agent').append(html);
        })
    }

    //   编辑代理
    $('.z_agent').on('click','.bianji',function(){
        location.href='zl_edit.html?id='+$(this).data('id');
    })

    //    删除代理
    $('.z_agent').on('click','.delz',function(){
        var that = this;
        dlctipbox.confirm('确定要删除代理？',function(index){
            if(index==1){
                dlctipbox.loading();
                dlc_request('/api/agent/deleteAgent', { agentId:$(that).data('idx') }, function(res) {
                    console.log(res)
                    dlctipbox.clear();
                    if(res.code==1){
                        dlctipbox.show('删除成功')
                        setTimeout(function(){
                            list("","");
                        },1500)
                    }
                })
            }
        })
    })
</script>